class CharacterTraitsController < ApplicationController
  before_filter :login_required
  
  def authorized?(user = current_player())
    return user.admin?
  end
  
  def destroy
    @character = Character.find (params[:character_id])
    @trait = @character.character_traits.find(params[:id])
    
    @trait.destroy
    
    respond_to do |format|
      flash[:notice]= 'Trait was successfully deleted.'
      format.html { redirect_to @character }
      format.js # renders destroy.js.rjs
    end
  end
  
  def create
    @trait = Trait.new
    @trait.character_id = params[:character_id]
    @trait.trait_id = params[:trait_id]
    @character = Character.find(@trait.character_id)
    respond_to do |format|
      if @trait.save
        flash[:notice] = "Trait was successfully created."
        format.html { redirect_to @character }
        format.js # renders create.js.rjs
      else
        format.html { redirect_to @character }
        format.js do
          render :update do |page| 
            page.redirect_to @character
          end
        end
      end
      
    end
  end
end